﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using FineUI;
using SDLITS.Model;
using SDLITS.Common;
using MySoft.Data;

namespace SDLITS.Web.SystemManage
{
    public partial class CardHistoryManage : CommonBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid(GetWhere());
            }
        }
        private void BindGrid(WhereClip wc)
        {
            Grid1.RecordCount = SDDbSession.Default.From<V_CardhistoryMemberinfo>().Where(wc).Count();
            List<V_CardhistoryMemberinfo> items = SDDbSession.Default.From<V_CardhistoryMemberinfo>().Where(wc).Page(Grid1.PageSize, (Grid1.PageIndex + 1)).ToList();
            Grid1.DataSource = items;
            Grid1.DataBind();
        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid(GetWhere());
        }

        protected void btn_search_Click(object sender, EventArgs e)
        {
            Grid1.PageIndex = 0;
            Grid1.Hidden = false;
            BindGrid(GetWhere());
        }
        protected WhereClip GetWhere()
        {
            WhereClip wc = WhereClip.All;
            if(!string.IsNullOrEmpty(txt_no.Text))
            {
                wc = wc && V_CardhistoryMemberinfo._.MemCardNo == txt_no.Text.Trim();
            }
            return wc;
        }
    }
}
